package com.itheima.demo;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.UserInfo;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.InputStream;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        //1.读取核心配置文件
        InputStream is = Resources.getResourceAsStream("sqlConfig.xml");
        //2.构建sqlSessionFactory对象(构建者模式)
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        //3.获取sqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //4.获取代理对象
        UserMapper mapper = sqlSession.getMapper(UserMapper.class);
        //5.调用方法
        UserInfo userInfo = mapper.findById(1);
        System.out.println(userInfo);
        //6.提交事务
        sqlSession.commit();
        //7.释放资源
        sqlSession.close();
    }
}
